<template>
	<view>
		<u-search
			v-model="keyword"
			:show-action="false"
			@change="searchlist"
			placeholder="请输入关键字"
		></u-search>
		<u-list @scrolltolower="scrolltolower" v-if="nodeData != false || status == 'loading'">
			<u-list-item v-for="(item, index) in nodeData" :key="index">
				<u-cell :title="(index+1)+'、'+ item.Name" :label="'类型:' + item.Type + ' 地址:' + (item.Model || '空')" isLink @click="toshowmodal(item.Id)">
				</u-cell>
			</u-list-item>
			<u-loadmore :status="status" v-if="loading" />
		</u-list>
		<u-modal title="数据" :show="modalshow" @confirm="connect" :closeOnClickOverlay="true"
			@close="modalshow = false,length = '',laytype=''">
			<u-form labelWidth="auto" labelPosition="top">
				<u-form-item label="到该缆线起点的皮长(米)"><u-input v-model="length" type="number" placeholder="请输入到该缆线起点的皮长(米)" /></u-form-item>
				<u-form-item label="至上一节点的敷设方式" @click="laytypeshow = true"><u-input disabled v-model="laytype"/></u-form-item>
			</u-form>
		</u-modal>
		<u-action-sheet :show="laytypeshow" :actions="columns" title="请选择类型" @close="laytypeshow = false"
			@select="changelaytype">
		</u-action-sheet>
		<u-toast ref="uToast" style="z-index: 999;"></u-toast>
	</view>
</template>

<script>
	import {
		getLinePathNodelist,
		addFiberNode,
	} from '@/common/api.js'
	import coordtransform from 'coordtransform'
	export default {
		data() {
			return {
				loading: true,
				user: {},
				keyword: "",
				Addr: "",
				fiberId: "",
				nodeData: [],
				index: "",
				region: "",
				filter: {},
				modalshow: false,
				laytypeshow: false,
				columns: [{name:'架空'},{name:'直埋'},{name:'管道'}],
				length: "",
				laytype: "",
				nodeId: ""
			}
		},
		onLoad(option) {
			console.log(option);
			this.user = JSON.parse(uni.getStorageSync("$userinfo"))
			this.fiberId = option.Id
			this.index = option.index
			this.region = option.region
			getLinePathNodelist(option.region,{Parameters: [],orderBys: ["CreateTime desc"],}).then(res => {
				this.nodeData = res.data
			})
		},
		methods: {
			searchlist(){
				let para = {}
				this.filter = {
					"ConditionalList": [{
						"Key": 0,
						"Value": {
							"FieldName": "Name",
							"FieldValue": this.keyword,
							"ConditionalType": "Like"
						}
					}, {
						"Key": 1,
						"Value": {
							"FieldName": "Type",
							"FieldValue": this.keyword,
							"ConditionalType": "Like"
						}
					}]
				}
				para.jsonPara=JSON.stringify( [this.filter])
				para.OrderBys = ["CreateTime desc"]
				getLinePathNodelist(this.region,para).then(res => {
					this.nodeData = res.data
				})
			},
			toshowmodal(Id){
				this.nodeId = Id
				this.modalshow = true
			},
			changelaytype(e) {
				this.laytype = e.name
			},
			connect(){
				let para = {
					fiberId: this.fiberId,
					nodeId: this.nodeId,
					length: this.length,
					layType: this.laytype
				}
				addFiberNode(this.index,para).then(res => {
					if (res.code == 0) {
						this.$refs.uToast.show({
							message: res.message,
							type: 'success',
							position: 'top',
							duration: 1000
						})
						uni.navigateBack({delta: 1})
					
					} else {
						this.$refs.uToast.show({
							message: res.message,
							type: 'error',
							position: 'top',
							duration: 1000
						})
					}
				})
			}
		},
	}
</script>

<style>

</style>